package com.ztjava.auth.validator;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.ztjava.core.Constant;
import com.ztjava.core.base.BaseValidator;
import com.ztjava.core.bean.sub.CaptchaBean;
import com.ztjava.ext.auth.annotation.UserController;
import com.ztjava.plugin.event.EventKit;
import com.ztjava.plugin.event.EventTag;
import com.ztjava.plugin.event.core.RequestEvent;
/***
 * 给其它模块使用的。自己没用
 * @author Administrator
 *
 */
public class AuthPhoneValidator extends BaseValidator {

	@Override
	protected void validate(Controller c) {
		String portal = c.getClass().getAnnotation(UserController.class).portal().toUpperCase();
		validateRequiredString("to",Constant.MESSAGE, "请输入手机号!");
		validateMobilePattern("to", Constant.MESSAGE, "手机号格式不正确！");
		validateRequiredString("auth",Constant.MESSAGE, "请输入短信验证码!");
		String auth_type = c.getPara("auth_type","PHONEBINDING");
		//检查验证码
		Ret ret = EventKit.postRemoteOnly(EventTag.COMMON_PUSH_CHECKCAPTCHA,
				new RequestEvent(new CaptchaBean(portal, c.getPara("to"),auth_type, c.getPara("auth"))));
		if(ret.getStr(Constant.RESULT).equals(Constant.ERROR)){
			addError(Constant.MESSAGE,ret.getStr(Constant.MESSAGE));
		}
	}

}
